#include "aliyun_mqtt.h"

// 连接阿里云函数实现
int Aliyun_MQTT_Connect(void)
{
    // 调用 ESP8266 连接服务函数
    return ESP8266_ConnectServer();
}

// 订阅主题函数实现
int Aliyun_MQTT_Subscribe(void)
{
    return ESP8266_SendCmd((unsigned char *)"AT+MQTTSUB=0,\"" SUB_TOPIC "\",0\r\n", strlen("AT+MQTTSUB=0,\"" SUB_TOPIC "\",0\r\n"), "OK");
}

// 处理接收数据函数实现
void Aliyun_MQTT_HandleReceivedData(void)
{
    if (receive_start == 1)
    {
        if (strstr((const char *)receive_buf, "+MQTTSUBRECV:")!= NULL)
        {
            // 在这里处理接收到的 MQTT 消息
            printf("Received MQTT message: %s\r\n", receive_buf);
        }
        // 清空接收缓冲区
        for (int i = 0; i < 512; i++)
        {
            receive_buf[i] = 0;
        }
        receive_count = 0;
        receive_start = 0;
        receive_finish = 0;
    }
}